package com.shengzai.rdd

import org.apache.spark.broadcast.Broadcast
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo24Bro {
  def main(args: Array[String]): Unit = {

    val conf = new SparkConf()

    conf.setAppName("Bro")

    conf.setMaster("local")

    val sc = new SparkContext(conf)

    val stuRDD: RDD[String] = sc.textFile("data/students.txt")

    val list: List[String] = List[String]("1500100013", "1500100015", "1500100017", "1500100102")

    //1.在Driver端将变量包装成广播变量
    val bro: Broadcast[List[String]] = sc.broadcast(list)

    val resRDD: RDD[String] = stuRDD.filter(
      line => {
        //2.在Executor端做出逻辑操作
        bro.value.contains(line.split(",")(0))
      }
    )
    resRDD.foreach(println)
  }
}
